package com.wms.helper;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Provides static methods for interfacing with the MySQL database for the application
 * @author Suki
 */
public class Database {

	private static final String hostname= "jdbc:mysql://WMSjellybean.db.9668874.hostedresource.com/WMSjellybean" ;
	private static final String username= "WMSjellybean" ;
	private static final String readuser= "WMSjellybeanRead";
	//private static final String dbname= "WMSjellybean" ;
	private static final String password= "Jellybean#2340";
	
	/**
	 * Provides a JDBC connection with the read-only username for the application database
	 * @return a usable JDBC connection
	 * @throws SQLException
	 * @throws InstantiationException only thrown when there are environment errors
	 * @throws IllegalAccessException only thrown when there are environment errors
	 * @throws ClassNotFoundException only thrown when there are environment errors
	 */
	public static Connection getReadConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		Connection connection = DriverManager.getConnection(hostname, readuser, password);
		return connection;
	}
	
	/**
	 * Provides a JDBC connection with the read/write username for the application database
	 * @return a usable JDBC connection
	 * @throws SQLException
	 * @throws InstantiationException only thrown when there are environment errors
	 * @throws IllegalAccessException only thrown when there are environment errors
	 * @throws ClassNotFoundException only thrown when there are environment errors
	 */
	public static Connection getWriteConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		Connection connection = DriverManager.getConnection(hostname, username, password);
		return connection;
	}
	
/*	
	public static ResultSet runQuery(String query) throws SQLException{
		Connection conn = getConnection();
		Statement statement = conn.createStatement();
		ResultSet result = statement.executeQuery(query);
		conn.close();
		return result;
		
	}
*/	
	
}
